/*
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 */
package com.ecarx.systemui.plugin.psd;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ecarx.systemui.plugin.R;
import com.ecarx.systemui.plugin.utils.AppUtils;
import com.ecarx.systemui.plugin.utils.LogUtils;

public class PsdNavigationBarView extends FrameLayout {

    private static final String TAG = "PsdNavigationBarView";
    private View mRootView;
    private ImageButton mPsdHomeBtn;
    private ImageButton mPsdNaviBtn;
    private ImageButton mTestBtn;


    public PsdNavigationBarView(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public PsdNavigationBarView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public PsdNavigationBarView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        mRootView = LayoutInflater.from(context).inflate(R.layout.widget_psd_navigation_bar_view, this, true);
        mPsdHomeBtn = mRootView.findViewById(R.id.psd_home_btn);
        mPsdNaviBtn = mRootView.findViewById(R.id.psd_navi_btn);
        mTestBtn = mRootView.findViewById(R.id.test_btn);
        initListener();
    }

    private void initListener() {
        mPsdHomeBtn.setOnClickListener(v -> {
            LogUtils.i(TAG, "Click PSD Dock Bar HOME");
            //AppUtils.sendHomeAppPanelBroadcast(getContext(), false, true);
            Context context = PsdBarsManager.getInstance().getPSDContext();
            AppUtils.startLauncher(context, false, false);
        });

        mPsdNaviBtn.setOnClickListener(v -> {
            LogUtils.i(TAG, "Click PSD Dock Bar NAVI");
            Context context = PsdBarsManager.getInstance().getPSDContext();
            AppUtils.startNavigation(context, false);
        });

        mTestBtn.setOnClickListener(v -> {
            LogUtils.i(TAG, "Click PSD Dock Bar TEST");
            Context context = PsdBarsManager.getInstance().getPSDContext();
            AppUtils.startSettings(context, false);
        });

    }


    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        LogUtils.d(TAG, ev.toString());
        return super.dispatchTouchEvent(ev);
    }

}
